Completed
Push — master ( 854a25...f9c943 )
by Thomas
32s
created

module.exports   A

Complexity

Conditions 1
Paths 4

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 3
rs 10
1
'use strict'
2
3
const inquirer = require('inquirer')
4
const Kits = require('../kits/Kits')
5
const Kit = require('../kits/Kit')
6
7
module.exports = function (kit, slug) {
8
  var questions = []
9
10
  if (!kit || !kit.length) {
11
    questions.push({
12
      type: 'list',
13
      name: 'kit',
14
      message: 'starter kit:',
15
      choices: function () {
16
        var done = this.async()
17
        Kits.list(function (list) {
18
          done(null, list)
19
        })
20
      },
21
      default: 'basic'
22
    })
23
  }
24
25
  // Slug is set
26
  if (!slug || !slug.length) {
27
    questions.push({
28
      type: 'input',
29
      name: 'slug',
30
      message: 'module name:',
31
      validate: function (value) {
32
        if (value.match(/^([a-z0-9-]+\/)?[a-z0-9-]+$/)) {
33
          return true
34
        }
35
36
        return 'Module name should only contain lowercase letters, numbers and dashes.'
37
      }
38
    })
39
  }
40
41
  // Need to ask for slug
42
  inquirer.prompt(questions).then(function (answers) {
43
    Kit.create(answers.kit || kit, answers.slug || slug)
44
  })
45
}
46